<template>
  <div class="app-container">
    <el-row v-loading="listLoading" :gutter="20">
      <el-col :span="8">
        <structure-tree
          :data-source="treeModelData"
          node-key="oid"
          :default-props="defaultProps"
          :default-expand-key="defaultExpandKeys"
          :default-check-key="defaultCheckKeys"
          :current-node-key="currentNodeKey"
          :icon="treeIcon"
          @change="clickNodeChange"
        ></structure-tree>
      </el-col>
      <el-col :span="16">
        <el-tabs
          v-model="activeName"
          type="border-card"
          @tab-click="handleClick"
        >
          <el-tab-pane key="baseInfo" name="first">
            <span slot="label">
              <svg-icon
                icon-class="title-base-info"
                class="tab-pane-label-class"
              ></svg-icon>
              基本信息
            </span>
            <el-alert
              style="margin-bottom: 10px"
              :title="checkNodeTipTxt"
              type="info"
              :closable="false"
            ></el-alert>
            <div class="filter-container" style="margin-bottom: 10px">
              <el-button
                v-show="currentCheckNodeData.objectType === 'classify'"
                v-waves
                class="filter-item"
                type="primary"
                icon="el-icon-plus"
                @click="handleCreate"
              >
                添加分类
              </el-button>
              <el-button
                v-show="currentCheckNodeData.objectType === 'classify'"
                v-waves
                class="filter-item"
                type="primary"
                icon="el-icon-plus"
                @click="modelHandleCreate"
              >
                添加模型
              </el-button>
              <el-button
                v-waves
                class="filter-item"
                style="margin-left: 10px"
                type="primary"
                icon="el-icon-edit"
                @click="handleUpdate"
              >
                编辑
              </el-button>
              <el-button
                v-waves
                class="filter-item"
                style="margin-left: 10px"
                type="warning"
                icon="el-icon-delete"
                @click="handleDelete"
              >
                删除
              </el-button>
              <!--              <cus-del-btn @ok="handleDelete"/>-->
            </div>

            <data-base-info :baseinfo="currentCheckNodeData"></data-base-info>
          </el-tab-pane>
          <!--            <el-tab-pane label="模型文件" key="modelFile" name="second" v-if="currentCheckNodeData.objectType === 'model'">-->
          <!--              <file-download :file-list="fileList"></file-download>-->
          <!--            </el-tab-pane>-->
          <el-tab-pane
            v-if="currentCheckNodeData.objectType === 'model'"
            key="calProject"
            name="third"
          >
            <span slot="label">
              <svg-icon
                icon-class="title-project"
                class="tab-pane-label-class"
              ></svg-icon>
              计算项目
            </span>
            <el-table
              v-loading="listLoading"
              :data="projectData"
              size="mini"
              fit
              element-loading-text="Loading"
              border
              highlight-current-row
              align="center"
            >
              <el-table-column
                :label="calculateDesc.name"
                prop="name"
                align="center"
                sortable
              ></el-table-column>
              <el-table-column
                :label="calculateDesc.workflowName"
                prop="workflowName"
                align="center"
              ></el-table-column>
              <el-table-column
                :label="calculateDesc.startTime"
                prop="startTime"
                align="center"
              ></el-table-column>
              <el-table-column
                :label="calculateDesc.createUser"
                prop="createUser"
                align="center"
              ></el-table-column>
              <el-table-column
                :label="calculateDesc.status"
                prop="status"
                align="center"
              ></el-table-column>
              <el-table-column
                :label="calculateDesc.percent"
                prop="percent"
                align="center"
              ></el-table-column>
              <el-table-column fixed="right" align="center" label="操作">
                <template slot-scope="scope">
                  <!--  v-if="this.global_checkBtnPermission(['sys:user:edit','sys:user:delete'])"   v-has="'sys:calculate:start'" -->
                  <el-button
                    size="mini"
                    type="primary"
                    icon="el-icon-video-play"
                    plain
                    @click="handleUpdate(scope.row)"
                  >
                    启动
                  </el-button>
                  <!--  v-has="'sys:calculate:stop'"-->
                  <el-button
                    size="mini"
                    type="primary"
                    icon="el-icon-video-pause"
                    plain
                    @click="handleUpdate(scope.row)"
                  >
                    停止
                  </el-button>
                  <!--                v-has="'sys:calculate:stop'"-->
                  <el-button
                    size="mini"
                    type="primary"
                    icon="el-icon-refresh"
                    plain
                    @click="handleUpdate(scope.row)"
                  >
                    重启
                  </el-button>
                  <cus-del-btn
                    v-has="'sys:user:delete'"
                    @ok="handleDelete(scope.row.oid)"
                  />
                </template>
              </el-table-column>
            </el-table>
          </el-tab-pane>
        </el-tabs>
      </el-col>
    </el-row>

    <!-- 分类模态框 -->
    <div class="dia">
      <el-dialog
        :close-on-click-modal="false"
        :visible.sync="dialogVisible"
        width="45%"
        @close="handleDialogClose"
      >
        <template slot="title">
          <div class="titleZise">
            <!--            <i :class="modelIcon[dialogStatus]" style="margin-right: 5px">  </i>-->
            <svg-icon icon-class="model-corner-add" />
            <span>{{ titleMap[dialogStatus] }}</span>
          </div>
        </template>
        <el-form
          ref="dataForm"
          :model="form"
          :rules="rules"
          label-width="100px"
        >
          <el-form-item :label="classifyDesc.parentName" prop="parentName">
            <el-input v-model="parentNodeName" disabled="disabled"></el-input>
          </el-form-item>
          <el-form-item :label="classifyDesc.preId" prop="preId">
            <el-input v-model="form.preId"></el-input>
          </el-form-item>
          <el-form-item :label="classifyDesc.name" prop="name">
            <el-input v-model="form.name"></el-input>
          </el-form-item>
          <el-form-item :label="classifyDesc.description" prop="description">
            <el-input v-model="form.description"></el-input>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取消</el-button>
          <el-button type="primary" @click="submitForm">提交</el-button>
        </span>
      </el-dialog>
    </div>
    <!-- model模态框 -->
    <div class="dia">
      <el-dialog
        :close-on-click-modal="false"
        :visible.sync="modelDialogVisible"
        width="60%"
        class="remarks"
        @close="handleDialogClose"
      >
        <template slot="title">
          <div class="titleZise">
            <!--            <i :class="modelIcon[modelDialogStatus]" style="margin-right: 5px">  </i>-->
            <svg-icon icon-class="model-add" />
            <span>{{ modelTitleMap[modelDialogStatus] }}</span>
          </div>
        </template>
        <el-form
          ref="modelForm"
          status-icon
          :inline="true"
          :model="modelForm"
          :rules="modelRules"
          label-width="30%"
        >
          <el-divider>
            <span style="color: #b5b4b4">编码信息</span>
          </el-divider>
          <el-form-item
            :label="modelDesc.organization"
            prop="organization"
            class="formItem normalInput"
          >
            <el-select
              v-model="modelForm.organization"
              size="medium"
              placeholder="请选择"
              :disabled="modelDialogStatus != 'create'"
            >
              <el-option
                v-for="item in orgs"
                :key="item.itemText"
                :label="item.itemValue"
                :value="item.itemText"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item
            :label="modelDesc.modelNum"
            prop="modelNum"
            class="formItem normalInput"
          >
            <el-input
              v-model="modelForm.modelNum"
              :disabled="modelDialogStatus != 'create'"
            ></el-input>
          </el-form-item>
          <el-form-item
            :label="modelDesc.speciality"
            prop="speciality"
            class="formItem normalInput"
          >
            <el-select
              v-model="modelForm.speciality"
              placeholder="请选择"
              :disabled="modelDialogStatus != 'create'"
            >
              <el-option
                v-for="item in spes"
                :key="item.itemText"
                :label="item.itemValue"
                :value="item.itemText"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item
            :label="modelDesc.modelNumPart"
            prop="modelNumPart"
            class="formItem normalInput"
          >
            <el-input
              v-model="modelForm.modelNumPart"
              :disabled="modelDialogStatus != 'create'"
            ></el-input>
          </el-form-item>
          <el-form-item
            :label="modelDesc.versionNum"
            prop="versionNum"
            class="formItem normalInput"
          >
            <el-input
              v-model="modelForm.versionNum"
              :disabled="modelDialogStatus != 'create'"
            ></el-input>
          </el-form-item>
          <el-form-item
            :label="modelDesc.freeNum"
            prop="freeNum"
            class="formItem normalInput"
          >
            <el-input
              v-model="modelForm.freeNum"
              :disabled="modelDialogStatus != 'create'"
            ></el-input>
          </el-form-item>
          <el-form-item
            v-if="modelDialogStatus === 'create'"
            align="right"
            style="width: 100%"
          >
            <el-button
              icon="el-icon-coordinate"
              type="primary"
              @click="create_pre_id"
            >
              生成模型编号
            </el-button>
          </el-form-item>
          <el-divider>
            <span style="color: #b5b4b4">基本信息</span>
          </el-divider>

          <el-form-item
            :label="modelDesc.preId"
            prop="preId"
            label-width="15%"
            class="longInput"
          >
            <el-input v-model="modelForm.preId" disabled></el-input>
          </el-form-item>
          <el-form-item
            :label="modelDesc.parentName"
            prop="parentName"
            class="formItem normalInput"
          >
            <el-input v-model="parentNodeName" disabled="disabled"></el-input>
          </el-form-item>

          <el-form-item
            :label="modelDesc.name"
            prop="name"
            class="formItem normalInput formItemMargin"
          >
            <el-input v-model="modelForm.name"></el-input>
          </el-form-item>
          <el-form-item
            label-width="15%"
            :label="modelDesc.description"
            prop="description"
            class="longInput"
          >
            <el-input
              v-model="modelForm.description"
              type="textarea"
            ></el-input>
          </el-form-item>
          <!--          <el-form-item :label="modelDesc.fileName" prop="fileName">-->
          <!--            <el-input v-model="modelForm.fileName" class="dialog-formitem-class"></el-input>-->
          <!--          </el-form-item>-->
          <el-divider>
            <span style="color: #b5b4b4">上传文件</span>
          </el-divider>
          <el-form-item
            :label="modelDesc.fileName"
            style=""
            prop="fileName"
            class="formItem normalInput"
          >
            <!--            <el-input v-model="modelForm.fileName" class="dialog-formitem-class"></el-input>-->
            <el-upload
              ref="upload"
              class=""
              :action="url.upload"
              :on-preview="handlePreview"
              :on-remove="handleRemove"
              :file-list="file"
              :on-success="handleSuccess"
              :headers="headers"
              :on-change="handleChange"
              :before-upload="beforeUpload"
            >
              <el-button
                icon="el-icon-upload"
                size="small"
                type="primary"
                plain
              >
                点击上传
              </el-button>
            </el-upload>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="modelDialogVisible = false">取消</el-button>
          <el-button type="primary" @click="modelSubmitForm">提交</el-button>
        </span>
      </el-dialog>
    </div>
  </div>
</template>

<script>
  import dataBaseInfo from './components/DataBaseInfo'
  //import fileDownload from './components/FileDownload'
  import structureTree from '@/components/StructureTree'
  import { deleteAction, getAction, postAction } from '@/api/action'
  import { getToken } from '@/utils/auth'
  import { putAction } from '../../api/action'

  // classify常量title
  const classifyDesc = {
    parentName: '父节点',
    preId: '分类编号',
    name: '分类名称',
    description: '描述',
  }

  // model常量title
  const modelDesc = {
    parentName: '父节点',
    preId: '模型编号',
    name: '模型名称',
    description: '描述',
    fileName: '模型文件',
    dataType: '数据类型',
    organization: '组织',
    modelNum: '型号',
    speciality: '专业',
    modelNumPart: '部件',
    versionNum: '版本编号',
    freeNum: '自由编号',
  }

  // 计算项目列表
  const calculateDesc = {
    name: '计算项目',
    workflowName: '工作流模型',
    startTime: '开始时间',
    createUser: '发起人',
    status: '状态',
    percent: '进度',
  }

  export default {
    name: 'ModelList',
    components: {
      //Download,
      dataBaseInfo,
      structureTree,
    },
    data() {
      //自定义校验规则
      var maxSize = (rule, value, callback) => {
        if (!value && rule.field != 'freeNum') {
          return callback(new Error('不能为空'))
        }
        let maxLength = 6 //最大位数,默认6位
        if (rule.field == 'organization') {
          maxLength = 5
        }
        if (rule.field == 'freeNum') {
          maxLength = 30
          if ((value = '')) {
            this.modelForm[rule.field] = ''
          }
        }
        if (value.length > maxLength) {
          return callback(new Error('不能大于' + maxLength + '位数'))
        } else {
          //不足6位的填充0到6位
          // let fill = '';
          // for (let i =0 ; i < maxLength - value.length ; i++){
          //   fill += "0";
          // }
          // this.modelForm[rule.field] = fill + this.modelForm[rule.field];
        }
        callback()
      }
      //不能为空
      var blankSpace = (rule, value, callback) => {
        if (!value) {
          return callback(new Error('不能为空'))
        }
        callback()
      }
      //校验ip地址
      var isIP = (rule, value, callback) => {
        var reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/
        if (!reg.test(value)) {
          return callback(new Error('请输入正确IP地址！'))
        }
        callback()
      }
      //文件是否上传成功
      var isupload = (rule, value, callback) => {
        if (!this.hasUpload && this.modelDialogStatus == 'create') {
          return callback(new Error('不能为空'))
        }
        callback()
      }
      return {
        headers: {
          contentType: 'multipart/form-data; charset=utf-8',
          'presoft-Token': getToken(),
        },
        calculateDesc: calculateDesc,
        projectData: [],
        checkNodeTipTxt: '当前选中的节点为 空',
        filterText: '',
        listLoading: true,
        // 节点树中选中的节点数据
        currentCheckNodeData: {},
        // 父节点名称显示
        parentNodeName: '',
        // 默认展开的节点
        defaultExpandKeys: [],
        // 默认选中的节点
        defaultCheckKeys: [],
        // 当前选中的节点oid
        currentNodeKey: '',
        fileList: [
          {
            key: 'aaaa',
            fileName: 'project_attach_1591586771855.txt',
          },
        ],
        activeName: 'first',
        // 结构树data
        treeModelData: [],
        defaultProps: {
          children: 'children',
          label: 'name',
        },
        url: {
          listPage: '/presoftasim/resourcedata/structure/tree',
          classifyDelete: '/presoftasim/resourcedata/classification/delete',
          classifyCreate: '/presoftasim/resourcedata/classification/create',
          classifyUpdate: '/presoftasim/resourcedata/classification/update',
          classifyDetail: '/presoftasim/resourcedata/classification/detail',
          modelDelete: '/presoftasim/resourcedata/modelversion/delete',
          modelCreate: '/presoftasim/resourcedata/modelversion/create',
          modelUpdate: '/presoftasim/resourcedata/modelversion/update',
          modelDetail: '/presoftasim/resourcedata/modelversion/detail',
          createPreId: '/presoftasim/resourcedata/modelversion/createPreId',
          getModelFromSelects:
            '/presoftasim/resourcedata/modelversion/getModelFromSelects',
          upload: 'http://localhost:18086/presoftasim/common/upload',
        },
        // classify 模态框title -------------classify---------------
        classifyDesc: classifyDesc,
        form: {
          parentName: undefined,
          parentOid: undefined,
          preId: undefined,
          name: undefined,
          description: undefined,
          versionNum: undefined,
          fileName: undefined,
        },
        titleMap: {
          update: '编辑分类',
          create: '创建分类',
        },
        dialogStatus: 'create',
        dialogVisible: false,
        rules: {
          //分类模态框校验规则
          preId: [
            { validator: blankSpace, trigger: 'blur' },
            { required: true, trigger: 'blur' },
          ],
          name: [
            { validator: blankSpace, trigger: 'blur' },
            ,
            { required: true, trigger: 'blur' },
          ],
        },

        // model 模态框title -------------model---------------
        modelDesc: modelDesc,
        modelTitleMap: {
          //模态框标题
          update: '编辑模型',
          create: '创建模型',
        },
        modelIcon: {
          //模态框图标
          create: 'model-corner',
          update: 'model-corner',
        },
        modelDialogStatus: 'create',
        modelDialogVisible: false,
        modelForm: {
          parentName: undefined,
          parentOid: undefined,
          preId: undefined,
          name: undefined,
          description: undefined,
          fileName: undefined,
          dataType: undefined,
          organization: undefined,
          modelNum: undefined,
          speciality: undefined,
          modelNumPart: undefined,
          versionNum: undefined,
          freeNum: undefined,
          createrPreId: undefined,
          createTime6: undefined,
          specialityName: undefined,
          organizationName: undefined,
          valutId: undefined,
          createUser: this.$store.state.user.id,
        },
        orgs: [], //modelForm中organization组织选项列表
        spes: [], //modelForm中speciality专业选项列表
        modelRules: {
          organization: [
            { validator: maxSize, trigger: 'change' },
            { required: true, trigger: 'blur' },
          ],
          modelNum: [
            { validator: maxSize, trigger: 'blur' },
            { required: true, trigger: 'blur' },
          ],
          speciality: [
            { validator: maxSize, trigger: 'change' },
            { required: true, trigger: 'blur' },
          ],
          modelNumPart: [
            { validator: maxSize, trigger: 'blur' },
            { required: true, trigger: 'blur' },
          ],
          versionNum: [
            { validator: maxSize, trigger: 'blur' },
            { required: true, trigger: 'blur' },
          ],
          freeNum: [{ validator: maxSize, trigger: 'blur' }],
          name: [
            { validator: blankSpace, trigger: 'blur' },
            { required: true, trigger: 'blur' },
          ],
          preId: [
            { validator: blankSpace, trigger: 'change' },
            { required: true, trigger: 'blur' },
          ],
          fileName: [{ validator: isupload, trigger: 'change' }],
        },
        file: [],
        hasUpload: false,
        // disableMixinCreated: true  // 不使用mixins自动加载数据
        treeIcon: {
          //tree列表图标
          classify: 'model-corner', //节点类型：图标
          model: 'model',
        },
      }
    },
    computed: {
      dynamicHeight: function () {
        // 40是box的margin-top和margin-bottom  35是页脚 footer高度
        return window.innerHeight > 710
          ? window.innerHeight - 40 - 35 + 'px'
          : '710px'
      },
    },
    watch: {
      //切换选中的节点时如果去往不同类型节点在active的tablepan变成第一个
      currentCheckNodeData: function (newValue, oldValue) {
        if (newValue.objectType !== oldValue.objectType) {
          this.activeName = 'first'
        }
      },
    },
    created() {
      this.getTreeModel()
    },
    methods: {
      handleRemove(file, fileList) {
        // console.log(file, fileList);
      },
      handlePreview(file) {
        // console.log(file);
      },
      beforeUpload(file) {
        this.hasUpload = true
        this.fileChange()
      },
      handleChange(file) {
        // this.file = [];
      },
      handleExceed(files, fileList) {
        // this.$message.warning(`当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
      },
      handleSuccess(res) {
        console.log(res)
        this.modelForm.fileName = res.data.originName
        this.modelForm.valutId = res.data.id
        this.hasUpload = true
        this.fileChange()
      },
      // 获取结构树数据
      getTreeModel(oid, method) {
        this.listLoading = true
        getAction(this.url.listPage).then((res) => {
          this.treeModelData = res.data
          this.listLoading = false
          // 默认行为
          if (this.treeModelData.length > 0) {
            // 设置默认展开第一个根节点,this.treeModelData[0].children[0].oid
            // this.defaultExpandKeys = [this.treeModelData[0].oid];
            this.defaultExpandKeys.push(this.treeModelData[0].oid)
            if (oid == undefined || oid == '') {
              this.clickNodeChange(this.treeModelData[0])
            }

            // this.defaultCheckKeys = [oid];
          }
          if (method == 'delete') {
            this.getCurrentNode(this.treeModelData, oid)
            this.currentNodeKey = oid
            this.defaultExpandKeys.push(this.currentCheckNodeData.oid)
          } else if (oid != undefined && oid != '') {
            this.getCurrentNode(this.treeModelData, oid)
            this.currentNodeKey = oid

            if (this.currentCheckNodeData.parentOid != '') {
              this.defaultExpandKeys.push(this.currentCheckNodeData.parentOid)
            }
            this.currentNodeKey = this.currentCheckNodeData.oid
          }
        })
      },
      getCurrentNode(items, oid) {
        for (let i in items) {
          if (items[i].oid == oid) {
            this.clickNodeChange(items[i])
            // this.currentCheckNodeData = items[i];
            return items[i]
          }
          if (items[i].children != null && items[i].children.length > 0) {
            this.getCurrentNode(items[i].children, oid)
          }
        }
      },

      // 点击节点选中事件
      clickNodeChange(data) {
        this.currentCheckNodeData = data
        // this.$refs.tree.setCheckedKeys([data.oid]);
        this.checkNodeTipTxt = '当前选中的节点为：' + data.name
      },
      // tab页面切换事件
      handleClick(tab, event) {
        // console.log(tab, event);
      },

      // 分类添加 ------------------------classify----------------------
      handleCreate() {
        this.resetForm()
        this.dialogStatus = 'create'
        this.dialogVisible = true
        this.form.parentId = this.currentCheckNodeData.oid
        this.parentNodeName = this.currentCheckNodeData.name
      },
      // 添加分类提交
      submitForm() {
        if (this.dialogStatus == 'create') {
          this.form.parentOid = this.currentCheckNodeData.oid
          this.$refs.dataForm.validate((valid) => {
            if (valid) {
              postAction(this.url.classifyCreate, this.form)
                .then((response) => {
                  if (response.code === 200) {
                    this.getTreeModel(response.data)
                    this.dialogVisible = false
                  }
                })
                .catch((err) => {
                  console.log(err)
                })
            }
          })
        } else if (this.dialogStatus == 'update') {
          this.$refs.dataForm.validate((valid) => {
            if (valid) {
              putAction(this.url.classifyUpdate, this.form)
                .then((response) => {
                  if (response.code === 200) {
                    this.getTreeModel(this.currentCheckNodeData.oid)
                    this.dialogVisible = false
                  }
                })
                .catch((err) => {
                  console.log(err)
                })
            }
          })
        }
      },
      // 清空分类form
      resetForm() {
        this.form = {
          preId: undefined,
          name: undefined,
          description: undefined,
          versionNum: undefined,
          fileName: undefined,
          parentOid: undefined,
        }
      },

      // 模型添加函数 ------------------------model----------------------
      modelHandleCreate() {
        this.getModelFromSelects()
        this.modelResetForm()
        this.modelDialogStatus = 'create'
        this.modelDialogVisible = true
        this.modelForm.parentOid = this.currentCheckNodeData.oid
        this.parentNodeName = this.currentCheckNodeData.name
      },
      clearModel: function () {
        this.form = {}
      },

      // 提交创建model对象
      modelSubmitForm() {
        if (this.modelDialogStatus == 'update') {
          this.$refs.modelForm.validate((valid) => {
            if (valid) {
              putAction(this.url.modelUpdate, this.modelForm)
                .then((response) => {
                  if (response.code === 200) {
                    this.getTreeModel(this.currentCheckNodeData.oid)
                    this.submitOk(response.message)
                    this.modelDialogVisible = false

                    this.modelResetForm()
                  } else {
                    this.submitFail(response.message)
                  }
                })
                .catch((err) => {
                  console.log(err)
                })
            }
          })
        } else if (this.modelDialogStatus == 'create') {
          this.$refs.modelForm.validate((valid) => {
            if (valid) {
              postAction(this.url.modelCreate, this.modelForm)
                .then((response) => {
                  if (response.code === 200) {
                    this.getTreeModel(response.data)
                    this.submitOk(response.message)
                    this.modelDialogVisible = false

                    this.modelResetForm()
                  } else {
                    this.submitFail(response.message)
                  }
                })
                .catch((err) => {
                  console.log(err)
                })
            }
          })
        }
      },
      // 清空模型form
      modelResetForm() {
        this.file = []
        this.modelForm = {
          parentName: undefined,
          parentOid: undefined,
          preId: undefined,
          name: undefined,
          versionNum: undefined,
          description: undefined,
          fileName: undefined,
          dataType: undefined,
          organization: undefined,
          modelNum: undefined,
          speciality: undefined,
          modelNumPart: undefined,
          freeNum: undefined,
          createrPreId: undefined,
          createTime6: undefined,
          specialityName: undefined,
          organizationName: undefined,
          valutId: undefined,
          createUser: this.$store.state.user.id,
        }
      },

      // model 和 classify 根据类型判断操作  --------------------合并方法------------------------
      // 分类和模型修改操作
      handleUpdate() {
        if (this.currentCheckNodeData.objectType === 'classify') {
          getAction(this.url.classifyDetail, {
            oid: this.currentCheckNodeData.oid,
          }).then((res) => {
            this.dialogStatus = 'update'
            this.dialogVisible = true
            this.form = res.data
            this.parentNodeName = res.data.parentName
          })
        } else {
          getAction(this.url.modelDetail, {
            oid: this.currentCheckNodeData.oid,
          }).then((res) => {
            this.modelDialogStatus = 'update'
            this.modelDialogVisible = true
            this.modelForm = res.data
            this.parentNodeName = res.data.parentName
          })
        }
      },

      // 分类和模型删除操作 1: classify  2: model
      handleDelete(oid) {
        var that = this
        this.$confirm('确定删除当前选中的节点?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        })
          .then(() => {
            if (that.currentCheckNodeData.objectType === 'classify') {
              deleteAction(that.url.classifyDelete, {
                oid: that.currentCheckNodeData.oid,
              }).then((res) => {
                // that.loadData();
                this.getTreeModel(this.currentCheckNodeData.parentOid, 'delete')
              })
            } else {
              deleteAction(that.url.modelDelete, {
                oid: that.currentCheckNodeData.oid,
              }).then((res) => {
                this.getTreeModel(this.currentCheckNodeData.parentOid, 'delete')
              })
            }
          })
          .catch(() => {
            this.$message({
              type: 'info',
              message: '已取消删除',
            })
          })
      },

      // 监听dialog关闭时的处理事件
      handleDialogClose() {
        this.file = []
        if (this.$refs['dataForm']) {
          this.$refs['dataForm'].clearValidate() // 清除整个表单的校验
        }
        if (this.$refs['modelForm']) {
          this.$refs['modelForm'].clearValidate() // 清除整个表单的校验
        }
        this.hasUpload = false
      },

      //生成72位编码
      create_pre_id: function () {
        //校验表单输入书否符合要求，若全部符合才向服务端发起请求
        let handle = true
        this.$refs['modelForm'].validateField(
          [
            'organization',
            'modelNum',
            'speciality',
            'modelNumPart',
            'versionNum',
            'freeNum',
          ],
          (errmessage) => {
            if (errmessage != '') {
              handle = false
              return console.log(errmessage)
            }
          }
        )
        if (handle) {
          this.modelForm.parentOid = this.currentCheckNodeData.oid
          this.modelForm.createUser = this.$store.state.user.id
          postAction(this.url.createPreId, this.modelForm)
            .then((response) => {
              if (response.code === 200) {
                this.modelForm.preId = response.data.preId
                this.modelForm.createrPreId = response.data.createrPreId
                this.modelForm.createTime6 = response.data.createTime6
                this.modelForm.dataType = response.data.dataType
                if (
                  this.modelForm.freeNum == '' ||
                  this.modelForm.freeNum == undefined
                ) {
                  this.modelForm.freeNum = response.data.freeNum
                }
                this.getValue()
              }
            })
            .catch((err) => {
              console.log(err)
            })
        }
      },
      //获取组织、专业名称
      getValue: function () {
        for (let i in this.orgs) {
          if (this.modelForm.organization == this.orgs[i].itemText) {
            this.modelForm.organizationName = this.orgs[i].itemValue
          }
        }
        for (let i in this.spes) {
          if (this.modelForm.speciality == this.spes[i].itemText) {
            this.modelForm.specialityName = this.spes[i].itemValue
          }
        }
      },
      //获取组织、专业选择列表
      getModelFromSelects: function () {
        getAction(this.url.getModelFromSelects, this.modelForm)
          .then((response) => {
            if (response.code === 200) {
              this.orgs = response.data.organization
              this.spes = response.data.speciality
            }
          })
          .catch((err) => {
            console.log(err)
          })
      },
      // 文件列表发生变化时触发校验
      fileChange: function () {
        this.$refs['modelForm'].validateField(['fileName'], (errmessage) => {})
      },
    },
  }
</script>
<style lang="scss">
  .remarks >>> .el-input__inner {
    /*border: 0px solid;*/
    position: relative;
    color: rgb(0, 0, 0);
    text-align: left;
    font-family: 'PingFang';
    font-size: 12px;
  }

  // 修改placeholderd的样式
  .remarks >>> .el-input__inner::-webkit-input-placeholder {
    color: rgba(121, 130, 148, 1);
    text-align: left;
    font-family: 'PingFang';
    font-size: 12px;
    position: relative;
  }
  /*修改el-input disabled状态下的字体颜色*/
  .rt-input ::v-deep .el-input__inner {
    color: rgb(92, 112, 234) !important;
    cursor: pointer;
  }

  .formItem {
    width: 45%;
  }
  .normalInput .el-form-item__content {
    width: 70%;
    margin: 0px;
  }
  .longInput .el-form-item__content {
    width: 85%;
  }
  .el-form-item {
    margin-right: 0px;
  }
  .longInput {
    width: 90%;
  }
  .el-select {
    width: 100%;
    margin: 0px;
  }
</style>
